package com.itheima.controller;

import com.itheima.common.constant.MessageConstant;
import com.itheima.common.entity.Result;
import com.itheima.pojo.Order;
import com.itheima.pojo.OrderReturn;
import com.itheima.pojo.OrderSubmit;
import com.itheima.service.OrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@Api(tags = "体检预约相关接口")
@RestController
@RequestMapping("/order")
public class OrderController {
    @Autowired
    private OrderService orderService;

    /**
     * 根据预约id查询体检预约信息
     * @param id
     * @return
     */
    @GetMapping("/findById")
    @ApiOperation("根据预约id查询体检预约信息")
    public Result findById(Integer id){
        log.info("根据预约id查询体检预约信息");
        OrderReturn order = orderService.findById(id);
        return new Result(true, MessageConstant.QUERY_ORDER_SUCCESS,order);
    }

    /**
     * 体检预约
     * @param orderSubmit
     * @return
     */
    @PostMapping("/submitOrder")
    public Result submitOrder(@RequestBody OrderSubmit orderSubmit){
        log.info("体检预约:{}",orderSubmit);
        Integer id;
        try {
            id = orderService.submitOrder(orderSubmit);
            return new Result(true,MessageConstant.ORDER_SUCCESS,id);
        } catch (Exception e) {
            throw new RuntimeException(e);
           // return new Result(true,MessageConstant.ORDER_FULL,null);
        }
    }
}
